package cn.lisens.thymeleaf.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.lisens.thymeleaf.entity.DashboardData;
import cn.lisens.thymeleaf.entity.Product;

@Controller
@RequestMapping("/dashboard")
public class DashboardController {

    @GetMapping
    public String dashboard(Model model) {
        DashboardData data = new DashboardData();
        Product item = new Product();
		item.setTitle("雪糕");
		item.setDescription("好吃的雪糕");
		data.getTopProducts().add(item);
		Product item2 = new Product();
		item2.setTitle("鸭梨");
		item2.setDescription("不好吃你别买");
		data.getTopProducts().add(item2);
        
        model.addAttribute("dashboardData", data);
        return "dashboard/overview";
    }

    @GetMapping("/api")
    @ResponseBody
    public DashboardData getDashboardData(@RequestParam String range) {
        return new DashboardData();
    }
}
